package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;

import java.util.ArrayList;


public class OtherStudentDao implements BaseStudentDao{
    private static ArrayList<Student> students = new ArrayList<>();
    static {
        Student stu1 = new Student("001", "张三", "18", "1999-11-11");
        Student stu2 = new Student("002", "李四", "20", "1995-1-11");
        Student stu3 = new Student("003", "王五", "25", "1990-4-1");
        students.add(stu1);
        students.add(stu2);
        students.add(stu3);
    }
    public boolean addStudent(Student stu) {
        students.add(stu);
        return true;
    }

    public Student[] findAllStudents() {
        Student[] stus=new Student[students.size()];
        for (int i = 0; i < stus.length; i++) {
            stus[i]=students.get(i);
        }
        return stus;
    }

    public void deleteStudentById(String id) {
        for (int i = 0; i < students.size(); i++) {
            Student s = students.get(i);
            if (s != null && s.getId().equals(id)) {
                students.remove(i);
                break;
            }
        }
    }

    public void updateStudentById(Student stu) {
        String id=stu.getId();
        for (int i = 0; i < students.size(); i++) {
            Student s = students.get(i);
            if (s!=null&&s.getId().equals(id)){
                students.set(i,stu);
                break;
            }
        }
    }
}
